<template>
	<view>
		<view class="header status_bar">
			<view class="back iconfont" @tap="backPage">&#xe779;</view>
			<view class="text">设置</view>
		</view>
		<view class="clear_box"></view>
		
		<view class="list_box">
			<block v-for="(item, index) in list" :key="'list' + index">
			<view class="list" hover-class="uni_list_go" :data-url="item.url" @click="gotopage">
				<view class="icon iconfont" :class="item.icon"></view>
				<view class="text">{{item.text}}<span class="bind" v-if="item.value">(已绑定)</span></view>
				<view class="value" v-if="item.value">{{item.value}}</view>
				<view class="arrow iconfont">&#xe775;</view>
			</view>
			</block>
			<!-- <view class="list" @tap="logoutAccounts">
				<view class="icon iconfont"></view>
				<view class="text">注销账号</view>
				<view class="arrow iconfont">&#xe775;</view>
			</view> -->
		</view>
		
		
		<!-- <button class="confirm" @tap="signOut">退出登录</button> -->
		

		
	</view>
</template>

<script>
export default {
	data() {
		return {
			list:[
				// {
				// 	icon:'iconyinhangqia',
				// 	text:'修改密码',
				// 	url:'/pages/subPack/personalcenter/set/modify'
				// },
				// {
				// 	icon:'iconyinhangqia',
				// 	text:'修改绑定手机号',
				// 	url:'/pages/subPack/personalcenter/set/phone',
				// 	value:'',
				// },
				// {
				// 	icon:'iconyinhangqia',
				// 	text:'修改绑定微信号',
				// 	url:'bindWx',
				// 	value:'',
				// },
				{
					icon:'iconmima',
					text:'用户协议和隐私政策',
					url:'/pages/personalcenter/privacy?type=' + 8
				},
				{
					icon:'iconmima',
					text:'平台注册协议',
					url:'/pages/personalcenter/privacy?type=' + 11
				},
				{
					icon:'iconmima',
					text:'服务协议',
					url:'/pages/personalcenter/privacy?type=' + 7
				},
				// {
				// 	icon:'iconguanyu',
				// 	text:'关于我们',
				// 	url:'/pages/subPack/personalcenter/aboutus'
				// },
				// {
				// 	icon:'iconqinglihuancun',
				// 	text:'清理缓存',
				// 	url:''
				// },
				
			],
			phone:'',
			bindWx:'',
		};
	},
	onLoad(e) {
		let that = this;
		console.log(e.phone);
		console.log(JSON.parse(e.wx));
		if(e.phone){
			that.list[1].value = e.phone;
		}
		if(JSON.parse(e.wx)){
			that.bindWx = JSON.parse(e.wx);
			that.list[2].value = that.bindWx.nickname;
		}
		
		
	},
	methods: {
		logoutAccounts(){
			let that = this;
			uni.showModal({
				title: '提示',
				content: '是否注销帐号?',
				success: function(res) {
					if (res.confirm) {
						//console.log('用户点击确定');
						that.Net._get(
							'cancellation',{},
							res => {
								//console.log(res);
								if (res.code == 200) {
									that.Msg.Success('注销帐号成功', res => {
										// that.Nav._to({ url: '/pages/public/login', type: 2 });
										uni.reLaunch({											
											url: '/pages/public/login'											
										});
									});
								}
							}
						);
					} else if (res.cancel) {
						//console.log('用户点击取消');
					}
				}
			});
			
		},
		signOut(){
			let that = this;
			uni.showModal({
				title: '提示',
				content: '是否退出登录',
				success: function(res) {
					if (res.confirm) {
						//console.log('用户点击确定');
						let token_ = 'Bearer ' + that.Net._getToken();
						that.Net._post(
							'logout',{},
							res => {
								//console.log(res);
								if (res.code == 200) {
									uni.setStorageSync('_TOKEN_', null);
									uni.setStorageSync('_AGREEMENT_', null);
									that.Msg.Success('退出登录成功', res => {
										// that.Nav._to({ url: '/pages/public/login', type: 2 });
										uni.reLaunch({											
											url: '/pages/public/login'											
										});
									});
								}
							}
						);
					} else if (res.cancel) {
						//console.log('用户点击取消');
					}
				}
			});
		},
		backPage() {
			uni.navigateBack({});
		},
		gotopage(e) {
			let that = this;
			let url = e.currentTarget.dataset.url;
			if(url == 'bindWx'){
				uni.showModal({
					title: '提示',
					content: '是否修改绑定微信',
					success: function (res) {
						if (res.confirm) {
							//console.log('用户点击确定');
							uni.getProvider({
								service: 'oauth',
								success: function(res) {
									//console.log(res.provider)
									if (~res.provider.indexOf('weixin')) {
										uni.login({
											provider: 'weixin',
											onlyAuthorize: true, // 微信登录仅请求授权认证
											success: function(loginRes) {
												//console.log(loginRes.code);
												// #ifdef APP-PLUS
												that.Net._post('oauth_bind_wx', { code: loginRes.code}, res => {
													if (res.code == 200) {
														//console.log(res);
														that.Msg.Success('微信绑定成功', res => {
															uni.navigateBack({});
														});
													} else if (res.code != 200) {
														that.Msg.Success(res.msg, res => {});
													}
												});
												// #endif
												// #ifdef MP-WEIXIN
												that.Net._post('oauth_bind_wx', { code: loginRes.code,oauth_name:'weixinmini'}, res => {
													if (res.code == 200) {
														//console.log(res);
														that.Msg.Success('微信绑定成功', res => {
															uni.navigateBack({});
														});
													} else if (res.code != 200) {
														that.Msg.Success(res.msg, res => {});
													}
												});
												// #endif
												
											}
										});
									}
								}
							});
						} else if (res.cancel) {
							//console.log('用户点击取消');
						}
					}
				});
				
				
			}else{
				uni.navigateTo({
					url: url
				});
			}
			
		},
		
		
	}
};
</script>

<style>
	page{
		padding-top: 1px;
	}
	
	.list_box{
		width: 100%;
		margin: 0 auto;
		background-color: #fff;
		/* border-radius: 4vw; */

	}
	
	.list_box .list{
		width: 100%;
		display: flex;
		border-bottom: 1px solid #F0F0F0;
	}
	
	.list_box .list:last-child{
		border: none;
	}
	
	.list_box .list .icon{
		width: 12vw;
		text-align: center;
		line-height: 16vw;
		height: 16vw;
		font-size: 5vw;
		color: #FF5301;
	}
	
	/* .list_box .list:nth-child(1) .icon{
		color: #45CA4A;
	}
	
	.list_box .list:nth-child(2) .icon{
		color: #FFA500;
	}
	
	.list_box .list:nth-child(3) .icon{
		color: #247BFF;
	}
	
	.list_box .list:nth-child(4) .icon{
		color: #926EFD;
	}
	
	.list_box .list:nth-child(5) .icon{
		color: #F28C00;
	}
	
	.list_box .list:nth-child(6) .icon{
		color: #4966F5;
	} */
	
	.list_box .list .arrow{
		width: 10.5vw;
		text-align: center;
		line-height: 16vw;
		height: 16vw;
		font-size: 3.5vw;
		color: #B3B3B3;
	}
	
	.list_box .list .text{
		flex: 1;
		font-size: 3.5vw;
		color: #333;
		line-height: 16vw;
		height: 16vw;
	}
	
	.list_box .list .value{
		font-size: 3.2vw;
		color: #666;
		line-height: 16vw;
		height: 16vw;
	}
	
	.list_box .list .text .bind{
		color: #ff7f22;
	}
	

</style>
